home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / diskBoot.OpenProm / fileLoad.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-14  |  3.1 KB  |  129 lines

  1. /* 
  2.  * fileLoad.c --
  3.  *
  4.  *    The routine to load a program into main memory.
  5.  *
  6.  * Copyright 1986 Regents of the University of California
  7.  * All rights reserved.
  8.  */
  9.  
  10. #ifdef notdef
  11. static char rcsid[] = "$Header: /sprite/src/boot/sunprom/RCS/fileLoad.c,v 1.10 90/11/27 11:17:25 jhh Exp $ SPRITE (Berkeley)";
  12. #endif not lint
  13.  
  14. #include "sprite.h"
  15. #include "fsBoot.h"
  16. #include "procMach.h"
  17. #include "machMon.h"
  18. #include "boot.h"
  19.  
  20. #define KERNEL_ENTRY 0x4000
  21.  
  22.  
  23. /*
  24.  *----------------------------------------------------------------------
  25.  *
  26.  * FileLoad --
  27.  *
  28.  *    Read in the kernel object file.  This is loaded into memory at
  29.  *    a pre-defined location (in spite of what is in the a.out header)
  30.  *    for compatibility with Sun/UNIX boot programs.  The Sprite kernel
  31.  *    expects to be loaded into the wrong place and does some re-mapping
  32.  *    to relocate the kernel into high virtual memory.
  33.  *
  34.  * Results:
  35.  *    The entry point.
  36.  *
  37.  * Side effects:
  38.  *    None.
  39.  *
  40.  *----------------------------------------------------------------------
  41.  */
  42.  
  43.  
  44. int
  45. FileLoad(handlePtr)
  46.     register Fsio_FileIOHandle    *handlePtr;
  47. {
  48.     ProcExecHeader    aout;
  49.     int            bytesRead;
  50.     register int    *addr;
  51.     register ReturnStatus status;
  52.     register int    i;
  53.     register int    numBytes;
  54.  
  55.     /*
  56.      * Read a.out header.
  57.      */
  58.  
  59.     status = Read(handlePtr, 0, sizeof(aout), &aout, &bytesRead);
  60.     if (status != SUCCESS || bytesRead != sizeof(aout)) {
  61.     Mach_MonPrintf("No a.out header");
  62.     goto readError;
  63.     } else if (aout.magic != PROC_OMAGIC) {
  64.     Mach_MonPrintf("A.out? mag %x size %d+%d+%d\n",
  65.         aout.magic, aout.code, aout.data, aout.bss);
  66.     return(-1);
  67.     }
  68.  
  69.     /*
  70.      * Read the code.
  71.      */
  72.  
  73.     numBytes = aout.code;
  74.     Mach_MonPrintf("Size: %d", numBytes);
  75. #if defined(sun4) && !defined(sun4c)
  76.     status = Read(handlePtr, PROC_CODE_FILE_OFFSET(aout), numBytes,
  77.               KERNEL_ENTRY + sizeof(aout), &bytesRead);
  78. #else
  79.     status = Read(handlePtr, PROC_CODE_FILE_OFFSET(aout), numBytes,
  80.               KERNEL_ENTRY, &bytesRead);
  81. #endif
  82.     if (status != SUCCESS) {
  83.     goto readError;
  84.     } else if (bytesRead != numBytes) {
  85.     goto shortRead;
  86.     }
  87.  
  88.     /*
  89.      * Read the initialized data.
  90.      */
  91.  
  92.     numBytes = aout.data;
  93.     Mach_MonPrintf("+%d", numBytes);
  94. #if defined(sun4) && !defined(sun4c)
  95.     status = Read(handlePtr, PROC_DATA_FILE_OFFSET(aout), numBytes,
  96.               KERNEL_ENTRY + aout.code + sizeof(aout), &bytesRead);
  97. #else
  98.     status = Read(handlePtr, PROC_DATA_FILE_OFFSET(aout), numBytes,
  99.               KERNEL_ENTRY + aout.code, &bytesRead);
  100. #endif
  101.     if (status != SUCCESS) {
  102. readError:
  103.     Mach_MonPrintf("\nRead error <%x>\n", status);
  104.     return(-1);
  105.     } else if (bytesRead != numBytes) {
  106. shortRead:
  107.     Mach_MonPrintf("\nShort read (%d)\n", bytesRead);
  108.     return(-1);
  109.     }
  110.  
  111.     /*
  112.      * Zero out the bss.
  113.      */
  114.  
  115.     numBytes = aout.bss;
  116.     Mach_MonPrintf("+%d\n", numBytes);
  117. #if defined(sun4) && !defined(sun4c)
  118.     addr = (int *) (KERNEL_ENTRY + aout.code + aout.data + sizeof(aout));
  119. #else
  120.     addr = (int *) (KERNEL_ENTRY + aout.code + aout.data);
  121. #endif
  122.     bzero(addr, numBytes);
  123. #if defined(sun4) && !defined(sun4c)
  124.     return (KERNEL_ENTRY + sizeof(aout));
  125. #else
  126.     return (KERNEL_ENTRY);
  127. #endif
  128. }
  129.